// import com.alibaba.druid.sql.ast.SQLArgument;
// import com.alibaba.druid.sql.ast.SQLExpr;
// import com.alibaba.druid.sql.ast.expr.SQLCharExpr;
// import com.alibaba.druid.sql.dialect.oracle.visitor.OracleASTVisitor;

// import java.util.ArrayList;
// import java.util.List;

#include "OracleExecuteImmediateStatement.h"
#include "../../../../ast/SQLArgument.h"
#include "../../../../ast/SQLExpr.h"
#include "../../../../ast/expr/SQLCharExpr.h"
#include "../../visitor/OracleASTVisitor.h"

OracleExecuteImmediateStatement::OracleExecuteImmediateStatement()
{
  arguments = std::make_shared<std::list<SQLArgument_ptr>>();
  into = std::make_shared<std::list<SQLExpr_ptr>>();
  returnInto = std::make_shared<std::list<SQLExpr_ptr>>();
}

OracleExecuteImmediateStatement::OracleExecuteImmediateStatement(string_ptr dynamicSql)
{
  this->setDynamicSql(dynamicSql);
}

// @Override
void OracleExecuteImmediateStatement::accept0(OracleASTVisitor_ptr visitor)
{
  if (visitor->visit(SharedObject(OracleExecuteImmediateStatement)))
  {
  }
  visitor->endVisit(SharedObject(OracleExecuteImmediateStatement));
}

SQLObject_ptr OracleExecuteImmediateStatement::clone()
{
  SQLObject_ptr clone_tmp = std::shared_ptr<OracleExecuteImmediateStatement>(new OracleExecuteImmediateStatement());
  std::shared_ptr<OracleExecuteImmediateStatement> x = std::dynamic_pointer_cast<OracleExecuteImmediateStatement>(clone_tmp);
  // OracleExecuteImmediateStatement_ptr x = OracleExecuteImmediateStatement_ptr(new OracleExecuteImmediateStatement());

  if (dynamicSql != nullptr)
  {
    x->setDynamicSql(std::dynamic_pointer_cast<SQLExpr>(dynamicSql->clone()));
  }

  for (SQLArgument_ptr arg : *arguments)
  {
    SQLArgument_ptr a2 = std::dynamic_pointer_cast<SQLArgument>(arg->clone());
    a2->setParent(x);
    x->arguments->push_back(a2);
  }

  for (SQLExpr_ptr e : *into)
  {
    SQLExpr_ptr e2 = std::dynamic_pointer_cast<SQLExpr>(e->clone());
    e2->setParent(x);
    x->into->push_back(e2);
  }

  for (SQLExpr_ptr e : *returnInto)
  {
    SQLExpr_ptr e2 = std::dynamic_pointer_cast<SQLExpr>(e->clone());
    e2->setParent(x);
    x->returnInto->push_back(e2);
  }

  return x;
}

SQLExpr_ptr OracleExecuteImmediateStatement::getDynamicSql()
{
  return dynamicSql;
}

void OracleExecuteImmediateStatement::setDynamicSql(SQLExpr_ptr dynamicSql)
{
  if (dynamicSql != nullptr)
  {
    dynamicSql->setParent(SharedObject(OracleExecuteImmediateStatement));
  }
  this->dynamicSql = dynamicSql;
}

void OracleExecuteImmediateStatement::setDynamicSql(string_ptr dynamicSql)
{
  this->setDynamicSql(SQLCharExpr_ptr(new SQLCharExpr(dynamicSql)));
}

SQLArgument_list_ptr OracleExecuteImmediateStatement::getArguments()
{
  return arguments;
}

SQLExpr_list_ptr OracleExecuteImmediateStatement::getInto()
{
  return into;
}

SQLExpr_list_ptr OracleExecuteImmediateStatement::getReturnInto()
{
  return returnInto;
}
